package com.jeecg.demo.api;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

import java.io.File;
import java.io.IOException;
import java.sql.CallableStatement;
import java.sql.SQLException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.sf.json.JSONObject;

import org.hibernate.Session;
import org.jeecgframework.core.enums.StoreUploadFilePathEnum;
import org.jeecgframework.core.util.DateUtils;
import org.jeecgframework.core.util.FileUtils;
import org.jeecgframework.core.util.LogUtil;
import org.jeecgframework.core.util.ResourceUtil;
import org.jeecgframework.core.util.StringUtil;
import org.jeecgframework.core.util.oConvertUtils;
import org.jeecgframework.jwt.util.ResponseMessage;
import org.jeecgframework.jwt.util.Result;
import org.jeecgframework.jwt.util.menu.ResponseMessageCodeEnum;
import org.jeecgframework.web.system.service.SystemService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.orm.hibernate4.SessionFactoryUtils;
import org.springframework.stereotype.Controller;
import org.springframework.util.FileCopyUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;
import com.jeecg.demo.entity.AppAboutEntity;
import com.jeecg.demo.entity.AppFeedbackEntity;
import com.jeecg.demo.entity.AppUserCollectionEntity;
import com.jeecg.demo.entity.AppVersionEntity;
import com.jeecg.demo.service.AppAboutServiceI;
import com.jeecg.demo.service.AppFeedbackServiceI;
import com.jeecg.demo.service.AppUserCollectionServiceI;
import com.jeecg.demo.util.CommonUtil;
import com.jeecg.demo.util.PropertiesUtil;

/**
 * @Title: Controller
 * @Description: 客户端拍卖接口
 * @author onlineGenerator
 * @date 2019-05-29 17:10
 * @version V1.0
 * 
 */
@Api(value = "auction", description = "客户端拍卖操作", tags = "appInfo")
@Controller
@RequestMapping("/auction")
public class AppAutionSign {
	private static final Logger logger = LoggerFactory.getLogger(AppAutionSign.class);

	@Autowired
	private SystemService systemService;

	/**
	 *拍卖列表信息
	 * 
	 * @return
	 */
	@RequestMapping(value = "/getAcceptOrderList", method = RequestMethod.GET)
	@ResponseBody
	@ApiOperation(value = "拍卖列表信息", produces = "application/json", httpMethod = "GET")
	public ResponseMessage<?> getAcceptOrderList(@RequestParam String userid,@RequestParam String poid) {
		StringBuffer sb = new StringBuffer();
		// 非本交易商应单列表
		String s1 = "select  t.AOTRADERID, t.aotradername, t.aoprice, t.aodate  from V_ECP_ACCEPTORDER t  where t.poid = ?  and t.AOTRADERID !=   (select u.orgid from soa_ecp.sys_user u  where u.userid =?)  order by t.aodate desc";
		// 本交易商应单列表
		String s2 = "  select t.aotradername as aoname, t.aoprice, t.aodate from V_ECP_ACCEPTORDER t  where t.poid = ? and t.AOTRADERID = (select u.orgid  from soa_ecp.sys_user u  where u.userid =?)";

		// 非本交易商排序
		String s3 = " select decode(s.AOTRADERID, (select u.orgid  from soa_ecp.sys_user u where u.userid = '52888'),  s.aotradername,'竞买人' || rownum) as aoname,  s.aoprice,   s.aodate    from ("
				+ s1 + ") s";
		sb.append("select a.*  from (" + s3);
		sb.append(" union all " + s2);
		sb.append(" ) a  order by a.aodate desc");
		List<Map<String,Object>> listmap=systemService.findForJdbc(sb.toString(), poid,userid,poid,userid);
	
		return Result.success(listmap);
				
	}
	/**
	 *是否报名
	 * 
	 * @return
	 */
	@RequestMapping(value = "/getState", method = RequestMethod.GET)
	@ResponseBody
	@ApiOperation(value = "是否报名", produces = "application/json", httpMethod = "GET")
	public ResponseMessage<?> getState(@RequestParam String userid,@RequestParam String poid) {
		String sql = "select t.zhaobpmbmid,t.poid,t.userid,t.qiyid,t.zhuangt,t.baomsj,t.lianxr,t.lianxdh,t.trademode,d.dicname from V_ECP_ZHAOBPMJY_BAOM t left join soa_ecp.sys_dict d on d.diccode=t.ZHUANGT and d.dictype='BAOMZT' where  t.userid=? and t.poid=?";
		List<Map<String,Object>> listmap=systemService.findForJdbc(sql, userid,poid);
		return Result.success(listmap);
				
	}
	/**
	 *拍卖公告分享
	 * 
	 * @return
	 */
	@RequestMapping(value = "/shareAuction", method = RequestMethod.GET)
	@ResponseBody
	@ApiOperation(value = "拍卖公告分享", produces = "application/json", httpMethod = "GET")
	public String shareAuction(@RequestParam String id) {
		//调用接口地址 返回数据
		String url=PropertiesUtil.getPropertiesValue("auctionUrl");
		url =url+"?getinfo=pmxq&INFO_ID="+id;
		String content = CommonUtil.httpRequest(url);
		if (oConvertUtils.isNotEmpty(content)) {
			 return content;
		}
		 return null;
	}
	
}

